#include <regex>
#include <iostream>
#include <string>

int main(){
    
    // std::string request = "GET /dys_helloworld/hello/login HTTP/1.1";
    std::string request = "GET /dys_helloworld/hello/login?user=dys&passwd=hello HTTP/1.1";

    std::smatch matches;
    // std::regex reg("(GET|POST|HEAD|PUT|DELETE) ([^?]*)\\?(.*) (.*)/(.*)");
    // std::regex reg("(GET|POST|HEAD|PUT|DELETE) ([^?]*)\\?(.*) (HTTP/1\\.[01])");
    std::regex reg("(GET|POST|HEAD|PUT|DELETE) ([^?]*)(?:\\?(.*))? (HTTP/1\\.[01])(?:\r\n|\n)?");
    
    bool ret = std::regex_match(request, matches, reg);
    if(ret == false){
        return -1;
    }
    for(auto &s : matches){
        std::cout << s << '\n';
    }
    return 0;
}